#!/usr/bin/env python
#coding=utf-8

from os import environ
from getpass import getpass
from CGIHTTPServer import CGIHTTPRequestHandler, test, SimpleHTTPServer



class MYHTTPRequestHandler(CGIHTTPRequestHandler):
    def do_OPTIONS(self):           
        self.send_response(200, "ok")
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
        self.send_header("Access-Control-Allow-Headers", "X-Requested-With,  Content-Type")
    def do_GET(self):           
        self.send_response(200, "ok")
        self.send_header("Content-type", "text/html; charset=UTF-8")
        self.end_headers()
        fstream = self.wfile
        html = '''

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
    <title>Hacking</title>
    <body>
        <h2>You are hacked!</h2>
    </body>
</html>
                '''
	fstream.write(html)
	fstream.close()


if __name__ == '__main__':
        environ['user'] = getpass('User:')
        environ['pwd'] = getpass('Pwd:')
        test(HandlerClass = MYHTTPRequestHandler)
